<!DOCTYPE html>
<meta charset="utf-8" />
<link rel="stylesheet" href="ace_v1.3/assets/css/ui.jqgrid.css" />


<div class="search_panel">
<form action="" method="post" id="custSearchForm" onsubmit="return pageSearch(this);">
	<div style="display: block;" class="widget-body ">
		<div class="widget-main">
			<div class="rowt">
				<div class="col-sm-12">
					<div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">商户名称:</label>
							<div class="search_input">
								<input id="custName" type="text" name="custName"
									placeholder="请输入商户名称">
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">商户编号:</label>
							<div class="search_input">
								<input id="custId" type="text" name="custId"
									placeholder="请输入商户编号">
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">合作商:</label>
							<div class="search_input">
								<input id="agentName" type="text" name="agentName"
									placeholder="请输入合作商名称">
							</div>
						</div>
						
						<div class="search_elm" style="margin-left: 0px;width: 220px">
							<label class="label_search">手机号:</label>
							<div class="search_input">
								<input id="custLogin" type="text" name="custLogin" 
									placeholder="请输入手机号">
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px;margin-right: 15px;width: 260px;">
						    <label class="label_search">注册时间:</label>
							<div class="input-group">
								<input type="text" class="form-control date-picker" name="startTime" data-date-format="yyyy-mm-dd" placeholder="起始时间" />
								<span class="input-group-addon">
									<i class="fa fa-exchange"></i>
								</span>
								<input type="text" class="form-control date-picker" name="endTime" data-date-format="yyyy-mm-dd" placeholder="结束时间" />
							</div>
						</div>
					<div class="search_elm" style="margin-left: 0px;">
							<label class="label_search" for="userName">商户状态:</label>
							<div class="search_input">
							    <select 
									 rel="obj.MERSTATUS"
						 			 location="local" 
									 name="custStatus" 
						 			id="custStatus" 
						 			data-placeholder="请选" style="width: 100px;vertical-align:middle;">
									<option value='' >--请选择--</option>
								 </select>
							</div>
						</div>
						<div class="search_button">
							<button class="btn btn-small btn_search" type="submit" title="搜索" >
								搜索
							</button>
							
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	</form>
</div>
	<div class="row">
		<div class="col-xs-12">
			<table id="grid-table"></table>

			<div id="grid-pager"></div>

			<div style="margin-top: 10px">
				<span id="auth_btn">
				
				<a class="btn btn-small btn-info"
					onclick="reportCust();"> <!-- 
					<i class="icon-envelope"></i> -->商户导出
				</a>
				<!-- <a class="btn btn-small btn-default"
					onclick="statusUpdate0();"> 启用
					<i class="icon-envelope"></i> 
				</a>
				<a class="btn btn-small btn-default"
					onclick="statusUpdate1();"> 
					<i class="icon-envelope"></i> 禁用
				</a> -->
				
				<a class="btn btn-small btn-default"
					onclick="lock();"> 锁定<!-- 
					<i class="icon-envelope"></i> --> 
				</a>
				<a class="btn btn-small btn-default"
					onclick="unlock();"> <!-- 
					<i class="icon-envelope"></i> -->解锁
				</a>
				<a class="btn btn-small btn-warning"
					onclick="selectMobile();"> <!-- 
					<i class="icon-envelope"></i> -->详细
				</a>
				<a class="btn btn-small btn-warning"
					onclick="selectAccount();"> <!-- 
					<i class="icon-envelope"></i> -->余额
				</a>
				<!--<a class="btn btn-small btn-warning"
					onclick="selectAccount();">
					同步到乐刷
				</a>-->
				</span> <span id="paging_bar" style="float: right"> </span>
			</div>

			<!-- PAGE CONTENT ENDS -->
		</div>
		<!-- /.col -->
	</div>
	<!-- /.row -->

	<!-- page specific plugin scripts -->
	<script type="text/javascript">
		var jqGrid;
		jQuery(function($) {
			var grid_selector = "#grid-table";
			var pager_selector = "#grid-pager";

			$(window).on(
					'resize.jqGrid',
					function() {
						$(grid_selector).jqGrid('setGridWidth',
								$(".page-content").width());
					})
			var parent_column = $(grid_selector).closest('[class*="col-"]');
			$(document).on(
					'settings.ace.jqGrid',
					function(ev, event_name, collapsed) {
						if (event_name === 'sidebar_collapsed'
								|| event_name === 'main_container_fixed') {
							setTimeout(function() {
								$(grid_selector).jqGrid('setGridWidth',
										parent_column.width());
							}, 0);
						}
					})
			jQuery(grid_selector).jqGrid({

				url : "mpomng/mobileMerManage/query.do",
				datatype : "json",
				height : '100%',
				width : '100%',
				colNames : ['商户名称', '商户编号','注册时间','证件类型','证件号码','商户类型', '手机号','认证状态','可否登陆','地址', '商户状态','上次登陆时间',
				            '所属合作商','所属合作商编号' ],
				colModel : [ {name : 'custName',     index : 'custName',     width : '100px' }, 
				             {name : 'custId',       index : 'custId',       width : '120px' }, 
				             {name : 'custRegDatetime',  index : 'custRegDatetime',   width : '150px',formatter : gridFormatByDate}, 
				             {name : 'certificateType',     index : 'certificateType',     width : '100px' , ditcKey:'CERTTYPE', formatter : gridFormatByDict},
				             {name : 'certificateNo',    index : 'certificateNo',    width : '180px' }, 
				             {name : 'custType',     index : 'custType',     width : '100px' , ditcKey:'CUSTTYPE', formatter : gridFormatByDict},
				             {name : 'usrMobile',    index : 'usrMobile',    width : '100px' }, 
				             {name : 'authStatus',   index : 'authStatus',   width : '80px' ,ditcKey:'REGSTATUS' ,formatter : gridFormatByDict}, 
				             {name : 'isLoginFlag',  index : 'isLoginFlag',   width : '80px', ditcKey:'LOGINSTATUS', formatter : gridFormatByDict }, 
				             {name : 'address',   index : 'address',   width : '100px' }, 
				             {name : 'custStatus',   index : 'custStatus',   width : '90px' ,ditcKey:'MERSTATUS', formatter : gridFormatByDict}, 
				             {name : 'lastOperTime',         index : 'lastOperTime',         width : '150px' ,formatter : gridFormatByDate}, 
				             {name : 'agentName',         index : 'agentName',         width : '150px' } ,
				             {name : 'agentId',         index : 'agentId',         width : '150px' }, 
				            ],
				viewrecords : true,
				rowNum : 10,
				rowList : [ 10, 20, 30 ],
				altRows : true,

				multiselect : true,//设置行可多选的 
				multiboxonly : true,//
				shrinkToFit:false,
				loadComplete : function() {
					var table = this;
					setTimeout(function() {
						//加载分页
						initPagingBar(grid_selector);
					}, 0);
				},
				beforeRequest : function() {//请求之前执行
					jqGrid = this;
				},
			});
			$(window).triggerHandler('resize.jqGrid');

			$(document).one('ajaxloadstart.page', function(e) {
				$(grid_selector).jqGrid('GridUnload');
				$('.ui-jqdialog').remove();
			});

			
		});
		function selectMobile() {
			var rows = $('#grid-table').jqGrid("getGridParam", "selarrrow");
			
			if (rows.length == 0) {
				msg.alert("警告", "当前没有选择数据项！", "error");
				return;
			}
			if (rows.length > 1) {
				msg.alert("警告", "不能同时选择多项数据！", "warn");
				return;
			}
			
			var ids = "";
			for (var i = 0; i < rows.length; i++) {
				ids += $('#grid-table').jqGrid('getRowData',rows[i]).custId+ ",";
			}
			ids = ids.substring(0, ids.lastIndexOf(","));
			var scrWidth = document.body.scrollWidth;
			openDialog({
				dialogId : 'dlg-agentEdit',
				title : '商户详细信息',
				pageUrl :'mpomng/mobileMerManage/view.do',
				dataUrl : 'mpomng/mobileMerManage/queryById.do',
				width :  scrWidth*0.8,
				dataParam : {
					custId : ids,
				},
				dataName : 'obj,map'//表单数据存储对象名称
			});
		}
		
		function selectAccount() {
           var rows = $('#grid-table').jqGrid("getGridParam", "selarrrow");
			if (rows.length == 0) {
				msg.alert("警告", "当前没有选择数据项！", "error");
				return;
			}
			if (rows.length > 1) {
				msg.alert("警告", "不能同时选择多项数据！", "warn");
				return;
			}
			
			var ids = "";
			for (var i = 0; i < rows.length; i++) {
				ids += $('#grid-table').jqGrid('getRowData',rows[i]).custId+ ",";
			}
			ids = ids.substring(0, ids.lastIndexOf(","));
			
			var scrWidth = document.body.scrollWidth;
			openDialog({
				dialogId : 'dlg-custAccountView',
				title : '商户账户信息',
				pageUrl :'mpomng/custAccountForCustView.do',
				width : '90%',
				height:'95%',
				pageParam : {
					custId : ids,
				},
				dataName : 'obj,map'//表单数据存储对象名称
			});
		}
		
	    function statusUpdate0(){
	    	setUserStatus(0);
	    }
	    function statusUpdate1(){
	    	setUserStatus(1);
	    }
	    
	    
	    function lock(){
	    	lockOrUnlock('01');
	    }
	    
	    function unlock(){
	    	lockOrUnlock('00');
	    }
	    
	    function lockOrUnlock(status){
		    var rows = $('#grid-table').jqGrid("getGridParam", "selarrrow");
			if (rows.length == 0) {
				msg.alert("警告", "当前没有选择的数据项,请选择数据！", "warn");
				return;
			}
			
			var ids="",uname="";
			var rowData ;
			for(var i=0; i<rows.length; i++){
				rowData = $('#grid-table').jqGrid('getRowData',rows[i]);
				ids   = ids+rowData.custId+",";
				uname = uname + rowData.custName+",";
			}
			ids   = ids.substring(0, ids.lastIndexOf(","));
			uname = uname.substring(0, uname.lastIndexOf(","));
			var tmsg = "解锁";
			if(status =='01'){
				tmsg = "锁定";
			}
			
			msg.confirm({title:'确认',position:'center',msg:'您确定要'+tmsg+'商户['+uname+']吗？',call:function(ok){
				if(ok){
					$.ajax({
						type : "post",
					    url : "mpomng/mobileMerManage/unlockLoginStatus.do?status="+status+"&ids="+ids,
						dataType : 'json',
						success : function(result) {
							if (result.rspcod != 200) {
								msg.alert("错误", result.rspmsg + " 错误代码："
										+ result.rspcod, 'error');
							} else {
								msg.alert("提示", result.rspmsg, 'correct');
								$("#grid-table").trigger("reloadGrid");
							}
						},
						error : function(XMLHttpRequest, textStatus) {
							msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："
									+ textStatus, 'error');
						}
					});
	
				}
			}});
			
		}
		function setUserStatus(status){
			var rows = $('#grid-table').jqGrid("getGridParam", "selarrrow");
			if (rows.length == 0) {
				msg.alert("警告", "当前没有选择的数据项,请选择数据！", "warn");
				return;
			}
			
			var ids="",uname="";
			var rowData ;
			for(var i=0; i<rows.length; i++){
				rowData = $('#grid-table').jqGrid('getRowData',rows[i]);
				ids   = ids+rowData.custId+",";
				uname = uname + rowData.custName+",";
			}
			ids   = ids.substring(0, ids.lastIndexOf(","));
			uname = uname.substring(0, uname.lastIndexOf(","));
			var tmsg = "启用";
			if(status == 1){
				tmsg = "禁用";
			}
			
			msg.confirm({title:'确认',position:'center',msg:'您确定要'+tmsg+'商户['+uname+']吗？',call:function(ok){
				if(ok){
					$.ajax({
						type : "post",
					    url : "mpomng/mobileMerManage/modifyCustStatus.do?status="+status+"&ids="+ids,
						dataType : 'json',
						success : function(result) {
							if (result.rspcod != 200) {
								msg.alert("错误", result.rspmsg + " 错误代码："
										+ result.rspcod, 'error');
							} else {
								msg.alert("提示", result.rspmsg, 'correct');
								$("#grid-table").trigger("reloadGrid");
							}
						},
						error : function(XMLHttpRequest, textStatus) {
							msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："
									+ textStatus, 'error');
						}
					});

				}
			}});
			
		}
		
	function report(){
		var sdate = "00000000";
		var edate = "99999999";
		var param = "";
		
		msg.confirm({title:'确认',position:'center',msg:'确认导出当前数据吗？',call:function(ok){
			if(ok){
				$.ajax({
					type : "post",
				    url : "mpomng/mobileMerManage/report.do?"+param,
					dataType : 'json',
					success : function(result) {
						if (result.rspcod != 200) {
							msg.alert("错误", result.rspmsg + " 错误代码："
									+ result.rspcod, 'error');
						} else {
							msg.alert("提示", result.rspmsg, 'correct');
						}
					},
					error : function(XMLHttpRequest, textStatus) {
						msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："
								+ textStatus, 'error');
					}
				});
			}
		}});
	}
	
	function reportCust(){
		var data = getFormParams($("#custSearchForm"));
		msg.confirm({title:'确认',position:'center',msg:'确认导出当前数据吗？',call:function(ok){
			if(ok){
				$.ajax({
					type : "post",
				    url : "mpomng/mobileMerManage/reportCust.do",
					dataType : 'json',
					data:data,
					success : function(result) {
						if (result.rspcod != 200) {
							msg.alert("错误", result.rspmsg + " 错误代码："
									+ result.rspcod, 'error');
						} else {
							msg.alert("提示", result.rspmsg, 'correct');
						}
					},
					error : function(XMLHttpRequest, textStatus) {
						msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："
								+ textStatus, 'error');
					}
				});
			}
		}});
	}
	
	 
	
	
	</script>